package com.framework.sensosr;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;

public class SenorsActivity extends Activity {
	SensorEventListener mListener = new SensorEventListener() {
		
		@Override
		public void onSensorChanged(SensorEvent event) {
			// TODO Auto-generated method stub
			if(event.sensor.getType() == Sensor.TYPE_ORIENTATION){
//				Log.d("com.framework.sensosr","d0 ===="+event.values[0]);
//				Log.d("com.framework.sensosr","d1 ===="+event.values[1]);
				Log.d("com.framework.sensosr","d2 ===="+event.values[2]);
			}
		}
		
		@Override
		public void onAccuracyChanged(Sensor sensor, int accuracy) {
			// TODO Auto-generated method stub
			
		}
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		Log.d("com.framework.sensosr","onCreate");
		if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
			int sensorType = Sensor.TYPE_ORIENTATION;
			sm.registerListener(mListener, sm.getDefaultSensor(sensorType), SensorManager.SENSOR_DELAY_NORMAL);
		}
		
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		Log.d("com.framework.sensosr","onConfigurationChanged ==== "+newConfig.orientation);
		if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		}
		super.onConfigurationChanged(newConfig);
	}
}
